package com.example.excise06.utils;

import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.InputStream;

public class ImageTools {
    //图片转Base64字符串
    public static final String imageToBase64(MultipartFile imgFile) {
        byte[] data = null;
        try {
            InputStream is = imgFile.getInputStream();
            data = new byte[is.available()];
            is.read(data);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
     BASE64Encoder encoder = new BASE64Encoder();
        return Base64.encodeBase64String(data);
    }
}